import {Injectable} from '@angular/core';
import * as API from "@api/index";
import {HttpService} from "@core/http/http.service";

import {SeoService} from "@core/seo/seo.service";
import {Response} from "@angular/http";
import {ToolsService} from "@shared/service/tools/tools.service";
import {FeedRespVO} from "@interface/index";


@Injectable()
export class FeedService {
  public dataStore = {
    feedComment: [] = [],
  };

  constructor(public httpService: HttpService,
              private _seoService: SeoService,
              private _tools: ToolsService) {

  }

  /**
   * @description 获取帖子详情
   * @author ouyqx-691
   * @date 2018/1/25
   * @param params 请求参数
   */
  getFeeds(params) {
    const url = API.FEED_URL + '?' + this._tools.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @description 获取帖子详情
   * @author ouyqx-691
   * @date 2018/1/25
   * @param params 帖子ID
   */
  getFeedDetail(feedId: number) {
    const url = API.FEED_ARTICLE_URL + `?feedId=${feedId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @description 获取资讯评论
   * @author ouyqx-691
   * @date 2018/1/25
   * @param params 请求参数
   */
  getFeedArticleComment(params) {
    const url = API.FEED_ARTICLE_COMMENT_URL +  '?' + this._tools.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @description 点赞
   * @author ouyqx-691
   * @date 2018/1/25
   */
  digg(data) {
    const url = API.FEED_ARTICLE_DIGG_URL;
    return this.httpService.postUrlencode(url, data).map((res) => res.json());
  }

  /**
   * @description 取消点赞
   * @author ouyqx-691
   * @date 2018/1/25
   * @param params 请求参数
   */
  cancelDigg(params) {
    const url = API.FEED_ARTICLE_DIGG_URL + '?' + this._tools.param(params);
    return this.httpService.delete(url).map((res: Response) => res.json());
  }
  // GetFeedArticleCommentDigg(commentId: number, userId: string, operation: boolean = true) {
  //   const data = {
  //     userId: userId,
  //     commentId: commentId
  //   };
  //   if (operation) {
  //     const url = API.FEED_ARTICLE_COMMENT_DIGG_URL;
  //     return this.httpService.postUrlencode(url, data).map((res: Response) => res.json());
  //   } else {
  //     const url = API.FEED_ARTICLE_COMMENT_DIGG_URL + `?userId=${userId}&commentId=${commentId}`;
  //     return this.httpService.delete(url).map((res: Response) => res.json());
  //   }
  // }
}
